<%@page import="com.carlyang.jspservlet.model.People"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello JSTL核心标签库</title>
</head>
<body>
<!-- 
JSTL（JSP Standard Tag Library ，JSP 标准标签库)
 -->
<h1><c:out value="JSP 标准标签库的核心标签"></c:out></h1>
<%
	pageContext.setAttribute("people", "王二小");
%>
<hr>
<h2>c:out</h2>
people：<c:out value="${people }" default="某人"> </c:out><br>
people2:<c:out value="${people2 }" default="某人"> </c:out>
<hr>
<h2>c:set</h2>
<c:set var="zhangsan" value="张三" scope="request"></c:set>
zhangsan：<c:out value="${zhangsan }"></c:out>
<jsp:useBean id="people2" class="com.carlyang.jspservlet.model.People" scope="page"></jsp:useBean>
<c:set property="id" target="${people2 }" value="002"></c:set>
<c:set property="name" target="${people2 }" value="王三小"></c:set>
<c:set property="age" target="${people2 }" value="12"></c:set>
people2编号：${people2.id }<br/>
people2姓名：${people2.name }<br/>
people2年龄：${people2.age }<br/>
<hr>
<h2>c:remove</h2>
<c:remove var="zhangsan"/>
<c:remove var="people"/>
people：<c:out value="${people }" default="某人"> </c:out><br>
people2:<c:out value="${people2 }" default="某人"> </c:out><br>
zhangsan：<c:out value="${zhangsan }" default="某人"></c:out>
<hr>
<h2>c:catch</h2>
<c:catch var="errMsg">
	<%
		int a = 1/0;
	%>
</c:catch>
int a = 1/0; 的异常信息：${errMsg }<br>
<hr>
<h2>c:if</h2>
<c:if test="${people2.name=='王三小' }" var="a" scope="page">
	people2.name是王三小
</c:if>
<c:if test="${people2.age<18 }" var="a" scope="page">
	people2.age 小于18
</c:if>
<hr>
<h2>c:chose c:when c:otherwise</h2>
<c:set property="age" target="${people2 }" value="20"></c:set>
people2:<c:out value="${people2 }" default="某人"> </c:out><br>
<c:choose>
	<c:when test="${people2.age < 18 }">
		people2.age 小于18
	</c:when>
	<c:when test="${people2.age == 18 }">
		people2.age 等于18
	</c:when>
	<c:otherwise>
		people2.age 大于18
	</c:otherwise>
</c:choose>
<hr>
<h2>c:forEach</h2>
<%
	String dogs[] = {"小黑","小白","小黄","小杂","小小"};
	pageContext.setAttribute("dogs", dogs);
%>
dogs:
<c:forEach var="a" items="${dogs}">
	${a}
</c:forEach><br>
dogs(step=2):
<c:forEach var="a" items="${dogs}" step="2">
	${a}
</c:forEach><br>
dogs(begin=2,end=3):
<c:forEach var="a" items="${dogs}" begin="2" end="4">
	${a}
</c:forEach><br>
<font color="blue" size="5" face="楷体">c:forEach 结合table输出:</font>
<%
	List<People> peopleList = new ArrayList<>();
	peopleList.add(new People(1,"carlyang",20));
	peopleList.add(new People(1,"yangdong",30));
	peopleList.add(new People(1,"杨东",25));
	peopleList.add(new People(1,"刘迅",25));
	peopleList.add(new People(1,"曾贵荣",26));
	pageContext.setAttribute("people", peopleList);//将属性值放到page属性中
%>
<table>
	<tr>
		<th>编号</th>
		<th>姓名</th>
		<th>年龄</th>
	</tr>
	<c:forEach var="p" items="${people }">
		<tr>
			<td>${p.id}</td>
			<td>${p.name}</td>
			<td>${p.age}</td>
		</tr>
	</c:forEach>
	<tr></tr>
</table>
<hr>
<h2>c:fortokens</h2>
<%
	String string1 = "www.carlyang.com";
	String string2 = "张三，李四，王五，apple";
	pageContext.setAttribute("str1", string1);
	pageContext.setAttribute("str2", string2);
%>
<c:forTokens items="${str1 }" delims="." var="s1">
	${s1}
</c:forTokens><br>
<c:forTokens items="${str2 }" delims="，" var="s1">
	${s1}
</c:forTokens>
<hr>
<h2>c:import</h2>
<c:import url="helloTag.jsp"></c:import>
<c:import url="index.jsp"></c:import>
<hr>
<!-- 
使用c:url只是使用该标签拼接一个超链接地址
 -->
<h2>c:url</h2>
<c:url value="http://localhost:8080/JspServlet/login" var="url">
	<c:param name="userName" value="test"></c:param>
	<c:param name="pwd" value="test123"></c:param>
</c:url>
已在链接后添加了参数userName，pwd，直接请求login动作就可以登录，而不是请求login.jsp网页<br><br>
<a href="${url }" target="_blank">jsp简单登录</a>
<hr>
<!-- 
重定向的功能,客户端跳转
 -->
<h2>c:redirect</h2>
<a href="c_redirect.jsp" target="_blank">c:redirect 客户端跳转</a>
<br><br>
<hr>
</body>
</html>